package org.soc.timesheet.server.domain.service;

import java.util.List;
import org.soc.timesheet.custom.annotation.AOPLogger;
import org.soc.timesheet.domain.Functions;
import org.soc.timesheet.domain.Roles;
import org.soc.timesheet.domain.repository.FunctionsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class FunctionsServiceImpl implements FunctionsService {

	@AOPLogger(name="service.Functions")
	public List<Functions> findByRolesesIn(List<Roles> roles){
		return functionsRepository.findByRolesesIn(roles);
	}
	
//	@Override
//	public List<Functions> findByRole(Roles idRole) {
//		// TODO Auto-generated method stub
//		return functionsRepository.findByRoleses(idRole);
//	}

	@Autowired
    FunctionsRepository functionsRepository;

	public long countAllFunctionses() {
        return functionsRepository.count();
    }

	public void deleteFunctions(Functions functions) {
        functionsRepository.delete(functions);
    }

	public Functions findFunctions(Integer id) {
        return functionsRepository.findOne(id);
    }

	public List<Functions> findAllFunctionses() {
        return functionsRepository.findAll();
    }

	public List<Functions> findFunctionsEntries(int firstResult, int maxResults) {
        return functionsRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void saveFunctions(Functions functions) {
        functionsRepository.save(functions);
    }

	public Functions updateFunctions(Functions functions) {
        return functionsRepository.save(functions);
    }
}
